<template>
  <el-dialog
    :title="type == 1? '转让群主':'设置群管理员'"
    :visible.sync="$attrs.visable"
    width="500px"
    :before-close="handleClose"
    append-to-body
  >
    <el-form
      ref="ruleForm"
      :model="form"
      :rules="rules"
      size="small"
      label-width="100px"
      label-position="left"
    >
      <div v-if="type == 1">
        <el-form-item label="转出企微号" prop="rollout">
          <el-select
            v-model="form.rollout"
            filterable
            remote
            :remote-method="remoteMethod"
            clearable
            :loading="loading"
            placeholder="所属企微号"
            style="width: 240px"
          >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="接收企微号" prop="receive">
          <el-select
            v-model="form.receive"
            filterable
            clearable
            placeholder="所属企微号"
            style="width: 240px"
          >
            <el-option label="区域一" value="shanghai"></el-option>
            <el-option label="区域二" value="beijing"></el-option>
          </el-select>
        </el-form-item>
      </div>
      <div v-if="type == 2">
        <el-form-item label="群主号" prop="rollout">
          <el-select
            v-model="form.rollout"
            filterable
            remote
            :remote-method="remoteMethod"
            clearable
            :loading="loading"
            placeholder="所属企微号"
            style="width: 240px"
          >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="管理员号" prop="receive">
          <el-select
            v-model="form.receive"
            filterable
            clearable
            placeholder="所属企微号"
            style="width: 240px"
          >
            <el-option label="区域一" value="shanghai"></el-option>
            <el-option label="区域二" value="beijing"></el-option>
          </el-select>
        </el-form-item>
      </div>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="handleClose">取 消</el-button>
      <el-button size="small" type="primary" @click="handleSubmit"
        >确 定</el-button
      >
    </span>
  </el-dialog>
</template>
<script>
export default {
  data() {
    return {
      loading: false,
      form: {
        rollout: "",
        receive: "",
      },
      rules: {
        rollout: [
          { required: true, message: "请选择转出企微号", trigger: "change" },
        ],
        receive: [
          { required: true, message: "请选择接收企微号", trigger: "change" },
        ],
      },
      optionsList:[
        { label: "满足任意一个标签", value: 1 },
        { label: "同时满足所有标签", value: 2 },
        { label: "未打标签", value: 3 },
      ],
      options: [],
    };
  },
  props:{
    type:{
      default:'', // 1 转让群主  2 设置群管
    }
  },
  created(){
    console.log('type:', this.type)
  },
  methods: {
    handleClose() {
      this.$emit("update:visable", false);
    },

    remoteMethod(query) {
      if (query !== "") {
        this.loading = true;
        setTimeout(() => {
          this.loading = false;
          this.options = this.optionsList.filter((item) => {
            console.log('item:', item)
            return item.label.toLowerCase().indexOf(query.toLowerCase()) > -1;
          });
        }, 200);
      } else {
        this.options = [];
      }
    },

    handleSubmit(){}
  },
};
</script>
<style lang="scss" scoped>
.tagbox {
  background-color: #f7f7f7;
  border-radius: 2px;
}
.checkbox {
  padding: 2px 16px;
  border-radius: 2px;
  border: 1px solid #f0f0f0;
}
</style>